/**
 * Copyright (c) Huawei Technologies Co., Ltd. 2023. All rights reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
#ifndef RUNTIME_KB_COMMON_UTILS_FILE_UTILS_H_
#define RUNTIME_KB_COMMON_UTILS_FILE_UTILS_H_

#include <fstream>
#include <string>
#include <sys/types.h>
#include <sys/stat.h>

#include "aoe/runtime_kb/common/kb_status.h"

namespace RuntimeKb {
constexpr mode_t kSafePermission = S_IRUSR | S_IWUSR | S_IRGRP;
class FileUtils {
 public:
  template <typename T>
  static Status OpenWithSafePermission(T& filestream, const std::string& filename,
                                       std::ios_base::openmode mode = std::ios_base::in | std::ios_base::out);
  static bool IsFileAccessedWithSafePermission(const std::string& filepath);
  static bool IsFileExist(const std::string& path);

 private:
  FileUtils() = default;
  ~FileUtils() = default;
  static int32_t Open(const std::string& path, const int32_t flags, const mode_t mode);
};
}  // namespace RuntimeKb
#endif
